package com.craftplay.dao;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.craftplay.model.Order;

public class OrderSqlProvider {

    public String insertSelective(Order record) {
        BEGIN();
        INSERT_INTO("payorder");
        
        if (record.getId() != null) {
            VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getOuttradeno() != null) {
            VALUES("outTradeNo", "#{outTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getUserid() != null) {
            VALUES("userId", "#{userId,jdbcType=INTEGER}");
        }
        
        if (record.getUnitid() != null) {
            VALUES("unitId", "#{unitId,jdbcType=INTEGER}");
        }
        
        if (record.getMoney() != null) {
            VALUES("money", "#{money,jdbcType=INTEGER}");
        }
        
        if (record.getCreatetime() != null) {
            VALUES("createTime", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }
        
        if (record.getPaytime() != null) {
            VALUES("payTime", "#{payTime,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(Order record) {
        BEGIN();
        UPDATE("payorder");
        
        if (record.getOuttradeno() != null) {
            SET("outTradeNo = #{outTradeNo,jdbcType=VARCHAR}");
        }
        
        if (record.getUserid() != null) {
            SET("userId = #{userId,jdbcType=INTEGER}");
        }
        
        if (record.getUnitid() != null) {
            SET("unitId = #{unitId,jdbcType=INTEGER}");
        }
        
        if (record.getMoney() != null) {
            SET("money = #{money,jdbcType=INTEGER}");
        }
        
        if (record.getCreatetime() != null) {
            SET("createTime = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }
        
        if (record.getPaytime() != null) {
            SET("payTime = #{payTime,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}